home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Sample Code / Movie Controller / MCComponent ƒ / MyComponent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-14  |  5.4 KB  |  225 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        MyComponent.c
  3.     
  4.     Contains:    simple component sample.
  5.  
  6.     Written by:    John Wang
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <1>        03/14/94    JW        Re-Created for Universal Headers.
  13.  
  14.     To Do:
  15.     
  16. */
  17.  
  18. #ifdef THINK_C
  19. #define        applec
  20. #endif
  21.  
  22. #include    <Memory.h>
  23. #include    <Errors.h>
  24. #include    <Components.h>
  25. #include    <Movies.h>
  26. #include    <QuickTimeComponents.h>
  27. #include    <Components.h>
  28. #include    <LowMem.h>
  29.  
  30. #include    "MyComponent.h"
  31. #include    "MyComponentRoutines.h"
  32.  
  33. /* ------------------------------------------------------------------------- */
  34.  
  35. //    Component entry point.
  36.  
  37. pascal ComponentResult main(ComponentParameters *params, char **storage)
  38. {
  39.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  40.     long                ret;
  41.     
  42.     if ( kDEBUGME )
  43.         DebugStr("\pIn main()");
  44.     
  45.     if ( params->what < 0 ) { 
  46.         switch ( params->what ) {
  47.             case kComponentOpenSelect:
  48.                 return ( CallComponentFunction(params, (ComponentFunctionUPP) MyOpen) );
  49.     
  50.             case kComponentCloseSelect:
  51.                 return ( CallComponentFunctionWithStorage(storage, params,
  52.                         (ComponentFunctionUPP) MyClose) );
  53.                 
  54.             case kComponentCanDoSelect:
  55.                 ret = CallComponentFunction(params, (ComponentFunctionUPP) MyCanDo);
  56.                 if ( ret == false ) {
  57.                     DebugStr("\pIn kComponentCanDoSelect");
  58.                     if ( (**myPrivateGlobals).delegate ) {
  59.                         ret = DelegateComponentCall(params, (**myPrivateGlobals).delegate);
  60.                     }
  61.                 }
  62.                 return ( ret );
  63.     
  64.             case kComponentVersionSelect: 
  65.                 return ( CallComponentFunction(params, (ComponentFunctionUPP) MyVersion) );
  66.     
  67.             case kComponentRegisterSelect: 
  68.                 return ( CallComponentFunctionWithStorage(storage, params,
  69.                         (ComponentFunctionUPP) MyRegister) );
  70.  
  71.             case kComponentTargetSelect: 
  72.                 return ( CallComponentFunctionWithStorage(storage, params,
  73.                         (ComponentFunctionUPP) MyTarget) );
  74.  
  75.             default:
  76.                 return ( paramErr );
  77.         }
  78.     } else {
  79.         switch ( params->what ) {
  80.             case kMCIsPlayerEventSelect:    
  81.                 return ( CallComponentFunctionWithStorage(storage, params,
  82.                         (ComponentFunctionUPP) MyIsPlayerEvent) );
  83.                             
  84.             default:
  85.                 if ( (**myPrivateGlobals).delegate ) {
  86.                     //    If base media handler is targeted, then delegate all unimplemented
  87.                     //    calls to the base media handler.
  88.                     long    ret;
  89.                     
  90.                     ret = DelegateComponentCall(params, (**myPrivateGlobals).delegate);
  91.                     return ( ret );
  92.                 } else {
  93.                     //    If base media handler has not been targeted, then return paramErr.
  94.                     return ( paramErr );
  95.                 }
  96.         }
  97.     }
  98. }
  99.  
  100. /* ------------------------------------------------------------------------- */
  101.  
  102. //    Required component calls.
  103.  
  104. pascal ComponentResult MyOpen(ComponentInstance self)
  105. {
  106.     PrivateGlobals             **myPrivateGlobals;
  107.     ComponentInstance        myComp;
  108.     ComponentDescription    searchComp;
  109.     Component                stdPlayer;
  110.     
  111.     if ( kDEBUGME )
  112.         DebugStr("\pIn MyOpen()");
  113.         
  114.     myPrivateGlobals = nil;
  115.     searchComp.componentType = 'play';
  116.     searchComp.componentSubType = 0;
  117.     searchComp.componentManufacturer = 'appl';
  118.     searchComp.componentFlags = 0x40000000;
  119.     searchComp.componentFlagsMask = 0x40000000;
  120.  
  121.     //    Open base media handler component and target it.
  122.     stdPlayer = FindNextComponent(nil, &searchComp);
  123.     if (stdPlayer == nil) {
  124.         DebugStr("\pCould not find standard movie controller.");
  125.     }
  126.     if ((myComp = OpenComponent(stdPlayer)) == nil) {
  127.         return(componentNotCaptured);
  128.     }
  129.     ComponentSetTarget(myComp, self);
  130.     
  131.     //    Create private variables.
  132.     myPrivateGlobals = (PrivateGlobals **) NewHandleClear(sizeof(PrivateGlobals));
  133.     if ( myPrivateGlobals == nil )
  134.         goto bail;
  135.     
  136.     //    Initialize private variables.
  137.     (**myPrivateGlobals).delegate = myComp;
  138.     (**myPrivateGlobals).fadeStatus = false;
  139.     (**myPrivateGlobals).firstTime = false;
  140.  
  141.     //    Since we've gotten here, everyt hings ok and we can set up the connection.
  142.     SetComponentInstanceStorage(self, (Handle) myPrivateGlobals);
  143.     return ( noErr );
  144.  
  145. bail:
  146.     if ( myPrivateGlobals )
  147.         DisposeHandle((Handle) myPrivateGlobals);
  148.     return ( memFullErr );
  149. }
  150.  
  151. pascal ComponentResult MyClose(Handle storage, ComponentInstance self)
  152. {
  153.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  154.  
  155.     if ( kDEBUGME )
  156.         DebugStr("\pIn MyClose()");
  157.  
  158.     //    Make normal again.
  159.     if ((**myPrivateGlobals).fadeStatus == true)
  160.         SwapWindow(myPrivateGlobals);
  161.         
  162.     //    Dispose of private variables.
  163.     if ( myPrivateGlobals ) {
  164.         if ((**myPrivateGlobals).delegate) {
  165.             CloseComponent((**myPrivateGlobals).delegate);
  166.             (**myPrivateGlobals).delegate = nil;
  167.         }
  168.         DisposeHandle((Handle) myPrivateGlobals);
  169.     }
  170.     
  171.     return ( noErr );
  172. }
  173.  
  174. pascal ComponentResult MyCanDo(short selector)
  175. {    
  176.     long    ret;
  177.  
  178.     if ( kDEBUGME )
  179.         DebugStr("\pIn MyCanDo()");
  180.     
  181.     switch ( selector ) {
  182.     
  183.         //    Required component calls.
  184.         case kComponentOpenSelect:
  185.         case kComponentCloseSelect:
  186.         case kComponentCanDoSelect:
  187.         case kComponentVersionSelect: 
  188.         case kComponentRegisterSelect: 
  189.         case kComponentTargetSelect: 
  190.  
  191.         //    MyComponent specific calls.
  192.         case kMCIsPlayerEventSelect:    
  193.             return ( true );
  194.  
  195.         //    Not handled.
  196.         default:
  197.             return ( false );
  198.     }
  199. }
  200.  
  201. pascal ComponentResult MyVersion()
  202. {
  203.     if ( kDEBUGME )
  204.         DebugStr("\pIn MyVersion()");
  205.  
  206.     return ( (kMyComponentSpec<<16) | (kMyComponentVersion) );
  207. }
  208.  
  209. pascal ComponentResult MyRegister()
  210. {
  211.     return ( false );
  212. }
  213.  
  214. pascal ComponentResult MyTarget(Handle storage, ComponentInstance self)
  215. {
  216.     PrivateGlobals         **myPrivateGlobals = (PrivateGlobals **) storage;
  217.  
  218.     if ( kDEBUGME )
  219.         DebugStr("\pIn MyTarget()");
  220.  
  221.     //    From now on, self will be the component instance that targeted us.
  222.     (**myPrivateGlobals).self = self;
  223.     
  224.     return ( noErr );
  225. }